﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.components {
    import flash.events.*;
    import flash.display.*;
    import flash.text.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.constants.*;

    public class Village extends AbstractView {

        private var m_currentPetID:String;
        private var m_isPlaying:Boolean;
        private var m_walkAnimation:MovieClip;
        private var m_levelTextfield:TextField;
        private var m_level:int;
        private var m_leavingHospitalQueue:Array;
        private var m_leavingVillageQueue:Array;

        public static const DIRECTION_GO_IN:String = "DIRECTION_GO_IN";
        public static const DIRECTION_GO_OUT:String = "DIRECTION_GO_OUT";

        public function Village(_arg1:String, _arg2:Number, _arg3:Number, _arg4:String){
            this.m_leavingHospitalQueue = [];
            this.m_leavingVillageQueue = [];
            super(_arg1, _arg2, _arg3, _arg4);
            cacheAsBitmap = true;
        }
        public function setLevel(_arg1:int):void{
            this.m_level = _arg1;
            var _local2:int = ((this.m_level > 6)) ? 6 : _arg1;
            MovieClip(_asset.house).gotoAndStop(("level" + _local2));
        }
        public function setNumberOfCuredPets(_arg1:int):void{
            this.m_levelTextfield.text = String(_arg1);
            this.m_levelTextfield.visible = (this.m_level >= 4);
        }
        public function showFireworks():void{
            MovieClip(_asset.house.rockets).play();
        }
        public function addPetToLeavingHospitalQueue(_arg1:String):void{
            this.m_leavingHospitalQueue.push(_arg1);
        }
        public function addPetToLeavingVillageQueue(_arg1:String):void{
            this.m_leavingVillageQueue.push(_arg1);
        }
        public function playPetLeavesVillage():void{
            if (this.m_isPlaying){
                return;
            };
            if (this.m_leavingVillageQueue.length > 0){
                this.m_currentPetID = this.m_leavingVillageQueue.shift();
                this.m_walkAnimation.addEventListener(Event.ENTER_FRAME, this.walkAnimation_enterFrame);
                this.m_isPlaying = true;
                this.m_walkAnimation.gotoAndPlay("go_hospital");
            };
        }
        public function playPetLeavesHospital():void{
            if (this.m_isPlaying){
                return;
            };
            if (this.m_leavingHospitalQueue.length > 0){
                this.m_currentPetID = this.m_leavingHospitalQueue.shift();
                this.m_walkAnimation.addEventListener(Event.ENTER_FRAME, this.walkAnimation_enterFrame);
                this.m_isPlaying = true;
                this.m_walkAnimation.gotoAndPlay("go_village");
            };
        }
        public function sendAmbulanceAway():void{
            this.m_walkAnimation.addEventListener(Event.ENTER_FRAME, this.walkAnimation_enterFrame);
            this.m_isPlaying = true;
            this.m_walkAnimation.gotoAndPlay("send_ambulance_away");
        }
        private function walkAnimation_enterFrame(_arg1:Event):void{
            var _local2:String = this.m_walkAnimation.currentLabel;
            if (_local2 == "on_arrival_at_hospital"){
                this.walkAnimationComplete();
                if (this.m_leavingVillageQueue.length == 0){
                    this.playPetLeavesHospital();
                } else {
                    this.playPetLeavesVillage();
                };
            } else {
                if (_local2 == "on_ambulance_door_open"){
                    this.walkAnimationComplete(EventConstants.ON_ARRIVAL_AT_HOSPITAL);
                } else {
                    if (_local2 == "on_arrival_at_village"){
                        this.walkAnimationComplete(EventConstants.ON_ARRIVAL_AT_VILLAGE);
                        if (this.m_leavingHospitalQueue.length == 0){
                            this.playPetLeavesVillage();
                        } else {
                            this.playPetLeavesHospital();
                        };
                    };
                };
            };
        }
        private function walkAnimationComplete(_arg1:String=null):void{
            this.m_walkAnimation.removeEventListener(Event.ENTER_FRAME, this.walkAnimation_enterFrame);
            this.m_isPlaying = false;
            this.m_walkAnimation.stop();
            if (_arg1){
                dispatchEvent(new InfoEvent(_arg1, this.m_currentPetID));
            };
        }
        override protected function initialize():void{
            this.m_walkAnimation = _asset.petAnimation;
            this.m_walkAnimation.gotoAndStop(1);
        }
        override protected function createChildren():void{
            super.createChildren();
            this.m_walkAnimation = _asset.petAnimation;
            this.m_walkAnimation.gotoAndStop(1);
            this.createTextfield();
        }
        private function createTextfield():void{
            this.m_levelTextfield = new TextField();
            this.m_levelTextfield.x = -5;
            this.m_levelTextfield.y = -8;
            addChild(this.m_levelTextfield);
            var _local1:TextFormat = new TextFormat();
            _local1.font = "MyriadProFont";
            _local1.align = TextFormatAlign.CENTER;
            _local1.bold = true;
            _local1.color = "0xFFCC32";
            _local1.size = 11;
            this.m_levelTextfield.embedFonts = true;
            this.m_levelTextfield.autoSize = TextFieldAutoSize.CENTER;
            this.m_levelTextfield.selectable = false;
            this.m_levelTextfield.defaultTextFormat = _local1;
        }
        public function setInOutAnimationVisible(_arg1:Boolean):void{
            this.m_walkAnimation.visible = _arg1;
        }

    }
}//package net.wooga.pets.views.components 
